package com.uniledger.exchange.wallet;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey;
import android.os.Parcel;
import android.os.Parcelable;

@Entity
public class WalletKey implements Parcelable {

    public long uid;

    @PrimaryKey(autoGenerate = true)
    public long id;//主键

    public String name;//钱包名称
    public String mnemonic;//助记词
    public String passphrase;//口令
    public int coinType;//数字货币类型
    public boolean isBackup;//是否已备份助记词
    public int mnemonicCount;
    public String accountId;

    @Ignore
    public String payUrl;

    @Ignore
    public String currency;

    @Ignore
    public WalletKey() {

    }

    @Ignore
    public WalletKey(String mnemonic, String accountId) {
        this.mnemonic = mnemonic;
        this.passphrase = "";
        this.accountId = accountId;
        this.coinType = 148;//Stellar
    }

    public WalletKey(String name, String mnemonic, String accountId) {
        this.name = name;
        this.mnemonic = mnemonic;
        this.passphrase = "";
        this.accountId = accountId;
        this.coinType = 148;//Stellar
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.uid);
        dest.writeLong(this.id);
        dest.writeString(this.name);
        dest.writeString(this.mnemonic);
        dest.writeString(this.passphrase);
        dest.writeInt(this.coinType);
        dest.writeByte(this.isBackup ? (byte) 1 : (byte) 0);
        dest.writeInt(this.mnemonicCount);
    }

    protected WalletKey(Parcel in) {
        this.uid = in.readLong();
        this.id = in.readLong();
        this.name = in.readString();
        this.mnemonic = in.readString();
        this.passphrase = in.readString();
        this.coinType = in.readInt();
        this.isBackup = in.readByte() != 0;
        this.mnemonicCount = in.readInt();
    }

    public static final Creator<WalletKey> CREATOR = new Creator<WalletKey>() {
        @Override
        public WalletKey createFromParcel(Parcel source) {
            return new WalletKey(source);
        }

        @Override
        public WalletKey[] newArray(int size) {
            return new WalletKey[size];
        }
    };
}
